package common

import (
	rand2 "crypto/rand"
	"fmt"
	"math/rand"
)

func GenerateSalt(length int) string {
	//rand.Seed(time.Now().UnixNano())
	letters := []rune("abcdefghijklmnopqrstuvwxyz0123456789")
	b := make([]rune, length)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	return string(b)
}

// GenerateAESKey 函数用于生成指定长度的AES密钥
func GenerateAESKey(length int) ([]byte, error) {
	if length != 16 && length != 24 && length != 32 {
		return nil, fmt.Errorf("无效的密钥长度，仅支持16、24或32字节")
	}
	key := make([]byte, length)
	_, err := rand2.Read(key)
	if err != nil {
		return nil, err
	}
	return key, nil
}
